/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.jr.wx.video.downloadagent.main;

import cn.ac.iie.di.ban.jr.wx.video.downloadagent.common.RuntimeEnv;
import static cn.ac.iie.di.ban.jr.wx.video.downloadagent.common.RuntimeEnv.jsonQueue;
import cn.ac.iie.di.ban.jr.wx.video.downloadagent.config.Configuration;
import cn.ac.iie.di.ban.jr.wx.video.downloadagent.handler.ParserFileHandler;
import cn.ac.iie.di.ban.jr.wx.video.downloadagent.handler.VideoDownloadThread;
import java.util.logging.Level;
import org.apache.log4j.Logger;

/**
 *
 * @author Administrator
 */
public class VideoDownloadAgentMain {

    static Logger logger = Logger.getLogger(VideoDownloadAgentMain.class.getName());

    public static void main(String[] args) {
        try {
            init();
            parserFile();
        } catch (Exception ex) {
            logger.fatal("start failed for" + ex.getMessage(),ex);
            System.exit(-1);
        }
    }

    public static void init() throws Exception {
        String configurationFileName = "config.properties";
        Configuration conf = Configuration.getConfiguration(ClassLoader.getSystemClassLoader().getResource(configurationFileName).getPath());
        if (conf == null) {
            logger.error("reading " + configurationFileName + " is failed.");
        }
        try {
            RuntimeEnv.initialize(conf);///参数，
            logger.info("init successfully");
        } catch (Exception ex) {
            logger.error("initializng runtime enviroment is failed for" + ex.getMessage());
        }
    }
        public static void parserFile() {
        String requestDir = (String) RuntimeEnv.getParam(RuntimeEnv.requestDir);
        if (!requestDir.endsWith("/")) {
            requestDir = requestDir + "/";
        }

        //美篇消息
        Thread parseThread = new Thread(new ParserFileHandler(requestDir));
        parseThread.setName("###Parser_video");
        parseThread.start();

    }

    
}
